package com.ostrich.note.ui.settings.views;

import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;

import android.os.Bundle;
import android.view.View;

import com.ostrich.note.R;
import com.ostrich.note.base.BaseMvvmActivity;
import com.ostrich.note.databinding.ActivitySettingsCollectBinding;
import com.ostrich.note.entity.BaseResponseEntity;
import com.ostrich.note.ui.note.adapter.NoteAdapter;
import com.ostrich.note.ui.note.entity.NoteEntity;
import com.ostrich.note.ui.settings.viewmodel.SettingsCollectViewModel;

import java.util.List;

public class SettingsCollectActivity extends BaseMvvmActivity<ActivitySettingsCollectBinding, SettingsCollectViewModel> {
    private NoteAdapter mNoteAdapter;
    @Override
    public void createViewModel() {
        viewModel = new ViewModelProvider(this).get(SettingsCollectViewModel.class);
    }


    @Override
    protected void iniView() {
        mNoteAdapter = new NoteAdapter();
        binding.rv.setAdapter(mNoteAdapter);
        binding.rv.setLayoutManager(new LinearLayoutManager(this));
    }

    @Override
    public int getLayout() {
        return R.layout.activity_settings_collect;
    }

    @Override
    public void initData() {
        viewModel.notepadCollectList().observe(this, new Observer<BaseResponseEntity<List<NoteEntity>>>() {
            @Override
            public void onChanged(BaseResponseEntity<List<NoteEntity>> listBaseResponseEntity) {
                if(listBaseResponseEntity.getCode() == 200){
                    mNoteAdapter.setData(listBaseResponseEntity.getData());
                }

            }
        });
    }

    @Override
    public void initListener() {
        binding.clBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

    }
}